<?php
namespace app\admin\controller;

use app\common\controller\BaseAdmin;
use app\common\model\SystemAdmin;
use app\common\model\Xtmessage as XtmessageModel;
use Illuminate\Support\Arr;
use LiteAdmin\Tree;
use think\Db;
use think\facade\Cache;
use think\facade\Session;

/**
 * @title 系统消息
 * Class Index
 * @package app\admin\controller
 */
class Xtmessage extends BaseAdmin
{
    /**
     * @title 系统消息
     * @auth 0
     * @return mixed
     * @throws \throwable
     */
    public function index()
    {
        $db = XtmessageModel::alias('u')
                ->join('content_user us','u.uid = us.id','left')

            ->field('u.*,us.uname')
            ->order('u.create_time desc');

        $search = $this->request->get();

        // 模糊查询
        foreach (['uname'] as $field){
            if (isset($search[$field]) && $search[$field] !== ''){
                $db->whereLike('us.'.$field, "%{$search[$field]}%");
            }
        }
        return $this->_list($db, true, $search);
    }
    /**
     * @title 添加操作
     * @return array|mixed
     */
    public function add()
    {

        return $this->_form(new XtmessageModel(), 'form');
    }
    /**
     * 添加前置
     * @param $data
     */
    protected function _add_form_before(&$data){
        if ($this->request->isPost()){
            $data['status'] = 1;
            $data['create_time'] = time();
        }
    }
    /**
     * @title 编辑操作
     * @return array|mixed
     */
    public function edit()
    {
        return $this->_form(new XtmessageModel(), 'form');
    }
    /**
     * @title 删除
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function del()
    {
        $ids = $this->request->post('ids');



        $this->_del(new XtmessageModel(), $ids);
    }
}
